var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
    value: true
});
var $2AudioManager = require("AudioManager");
var $2BulletMgr = require("BulletMgr");
var $2BundleManager = require("BundleManager");
var $2ZombieMgr = require("ZombieMgr");
var $2SceneStage = require("SceneStage");
var $2KDefine = require("KDefine");
var $2MyUtils = require("MyUtils");
var $2BulletBase = require("BulletBase");
var $2PlantBase = require("PlantBase");
var g = cc._decorator.ccclass;
var def_Plant10 = /* */ function(_u$default) {
    babel_inherits(p, _u$default);
    var _super62 = babel_createSuper(p);

    function p() {
        babel_classCallCheck(this, p);
        return _super62.apply(this, arguments);
    }
    babel_createClass(p, [{
        key: "shoot",
        value: function shoot() {
            var _this137 = this;
            var e = this;
            if (0 == this.remainCD) {
                var _t36 = this.dragon.setAnimation(0, "dazhao", true);
                this.dragon.setCompleteListener(function() {
                    e.setState($2KDefine.State.wait);
                    _this137.attackTimes += _this137.attackCD;
                    _this137.remainCD = _this137.skillCD;
                });
                this.dragon.setTrackEventListener(_t36, function(e, t) {
                    "dazhao" == t.data.name && _this137.attack(true);
                });
            } else {
                var _t37 = this.dragon.setAnimation(0, "gongji", true);
                var _a24 = 0;
                this.dragon.setCompleteListener(function() {
                    ++_a24 == _this137.attackNums && e.setState($2KDefine.State.wait);
                });
                this.dragon.setTrackEventListener(_t37, function(t, a) {
                    if ("gongji" == a.data.name) {
                        var _t38 = new cc.Vec2(_this137.node.getPosition().x + _this137.shootPo.x, _this137.node.getPosition().y + _this137.shootPo.y);
                        $2AudioManager.default.instance.playEffect(_this137.shootSound, _this137.shootSoundVolume);
                        $2BulletMgr.default.shoot_to_right($2SceneStage.default.instance.groudNode, _t38, e.bulletId, e.damage, e.attDistance, e.attackSpeed, _this137.hitSound, _this137.hitSoundVolume);
                    }
                });
                this.attackTimes += this.attackCD;
            }
        }
    }, {
        key: "attack",
        value: function attack() {
            var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
            if (!this.getZombie()) {
                return;
            }
            var t;
            var a = new cc.Vec2(this.getZombie().x - 40, this.getZombie().y - 40);
            var n = new cc.Vec2(this.node.getPosition().x + this.skillPos.x, this.node.getPosition().y + this.skillPos.y);
            var l = new cc.Vec2(n.x + (a.x - n.x) / 2, n.y + 600);
            if (e) {
                t = $2BulletMgr.default.instance().getItem(this.skillbullet, this.damage, this.hitSound, this.hitSoundVolume).node;
                $2AudioManager.default.instance.playEffect(this.skillSound, this.skillSoundVolume);
            } else {
                t = $2BulletMgr.default.instance().getItem(this.bulletId, this.damage, this.hitSound, this.hitSoundVolume).node;
                $2AudioManager.default.instance.playEffect(this.shootSound, this.shootSoundVolume);
            }
            t.parent = $2SceneStage.default.instance.groudNode;
            t.getComponent(cc.CircleCollider).enabled = false;
            t.setPosition(n);
            t.angle = 90;
            t.zIndex = $2KDefine.ZIndex.bullet;
            t.opacity = 255;
            cc.tween(t).parallel(cc.tween(t).bezierTo(1.5 / this.attackSpeed, n, l, a), cc.tween(t).to(1.5 / this.attackSpeed, {
                angle: -45
            })).call(function() {
                var e = t.getChildByName("bulletEffect").getComponent(sp.Skeleton);
                t.getComponent(cc.CircleCollider).enabled = true;
                t.getChildByName("bulletEffect").active = true;
                t.getComponent(sp.Skeleton).enabled = false;
                t.angle = 0;
                e.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "effect/" + t.getComponent($2BulletBase.default).bulletEffect + "/" + t.getComponent($2BulletBase.default).bulletEffect, sp.SkeletonData);
                e.setAnimation(0, "newAnimation", false);
                e.setCompleteListener(function() {
                    t.getChildByName("bulletEffect").active = false;
                    $2BulletMgr.default.instance().removeBullet(t.getComponent($2BulletBase.default));
                    e.setCompleteListener(null);
                });
            }).start();
        }
    }, {
        key: "getZombie",
        value: function getZombie() {
            var e = babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values()).length;
            var t = $2MyUtils.MyUtils.getRandomInt(0, e);
            if (babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[t]) {
                return babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[t].node.getPosition();
            } else {
                return null;
            }
        }
    }, {
        key: "checkTarget",
        value: function checkTarget() {
            if (0 == this.remainCD) {
                return 0 != $2ZombieMgr.default.instance().zombieNums;
            } {
                var _e67 = $2ZombieMgr.default.instance().zombieInRow[this.row];
                if (_e67.size <= 0) {
                    return false;
                }
                var _t39 = _e67.values();
                var _a25 = _t39.next();
                for (; !_a25.done;) {
                    var _e68 = _a25.value;
                    if (_e68.hp > 0 && _e68.node.x > this.node.x) {
                        return true;
                    }
                    _a25 = _t39.next();
                }
                return false;
            }
        }
    }]);
    return p;
}($2PlantBase.default);
def_Plant10 = cc__decorate([g], def_Plant10);
exports.default = def_Plant10;